package com.baidu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baidu.entity.PageResult;
import com.baidu.entity.QueryPageBean;
import com.baidu.mapper.HealthPlanMapper;
import com.baidu.pojo.HealthPlan;
import com.baidu.service.HealthPlanService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service(interfaceClass = HealthPlanService.class)
@Transactional
public class HealthPlanServiceImpl implements HealthPlanService {
	@Autowired
	private HealthPlanMapper HealthPlanMapper;


	@Override
	public PageResult pageQuery(QueryPageBean queryPageBean) {
		PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());//会自动的添加limit关键字

		//使用分页助手之后，limit0,10 。这个条件就不用我们写了。我们只用写 limit之前的语句

		Page<HealthPlan> page= HealthPlanMapper.pageQuerybyCondition(queryPageBean.getQueryString());//该Page对象是分页助手帮助我们封住的对象。

		PageResult pageResult = new PageResult(page.getTotal(),page.getResult());

		return pageResult;
	}

	@Override
	public void delete(Integer id) {

		HealthPlanMapper.delete(id);
	}

	@Override
	public void add(HealthPlan healthPlan) {
		HealthPlanMapper.add(healthPlan);

	}

	@Override
	public HealthPlan findById(Integer id) {
		return HealthPlanMapper.findById(id);
	}

	@Override
	public void edit(HealthPlan healthPlan) {
		HealthPlanMapper.edit(healthPlan);
	}


}
